package com.example.research.repository;

import com.example.research.model.Research;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;

public interface ResearchRepository extends JpaRepository<Research, Integer> {
    List<Research> findByTeacherTeacherId(Integer teacherId);
    List<Research> findByResearchTypeTypeId(Integer typeId);

    @Query("SELECT r FROM Research r WHERE r.teacher.name LIKE %?1% OR r.title LIKE %?1%")
    List<Research> search(String keyword);

    @Query("SELECT COUNT(r) FROM Research r WHERE r.teacher.teacherId = ?1 AND r.researchType.typeId = ?2")
    Long countByTeacherAndType(Integer teacherId, Integer typeId);
}